<!-- 我的权益 -->
<template>
	<view class="myRights">
		<view class="personal_jkhz_bg">
			<image src="@/static/images/index/personal_jkhz.png" mode="" style="width: 100%;"></image>
			<view class="status">已激活</view>
		</view>
		<view style="padding: 20rpx;padding-top: 0rpx;height: 52vh;overflow-y: auto;">
			<view class="hdsIGN">
				<h3>基本信息</h3>
			</view>
			<view class="hdsIGN_connent">
				<view v-for="(item,index) in equityData" :key="index" class="viewLi">
					<text>{{item.title}}</text>
					<text style="float: right;">{{item.value}}</text>
				</view>
			</view>
			<view class="hdsIGN">
				<h3>专属权益</h3>
			</view>
			<view class="hdsIGN_connent">
				<view v-for="(item,index) in exclusiveRights" :key="index" class="">
					<view class="viewLis" @click="btnItemDetails(item)">
						<image :src="item.img" mode="" style="width: 50rpx;height: 50rpx;"></image>
						<text>{{item.title}}</text>
						<uni-icons style="float: right;color: rgb(153, 153, 153);" type="right" size="26"></uni-icons>
					</view>
					<view class="viewChild">
						<view v-for="(child,id) in item.children" :key="id" class="">
							<text class="circular"></text>
							<text>{{child.text}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="position: absolute;bottom: 0rpx;left: 0rpx;width: 100%;background: #fff;">
			<button style="margin: 20rpx;" class="plainlk1" @click="shareToggle">联系客服</button>
		</view>
		<uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
			<!-- <uni-popup-share></uni-popup-share> -->
			<view class="shareview">客服热线</view>
			<view class="shareview">400-806-7176</view>
			<button @click="closeDrawer" style="margin: 20rpx;" class="plainlk1">取消</button>
		</uni-popup>
	</view>
</template>

<script>
	import {
		BeneficiariesList,
		ProductPrivileges
	} from '@/api/system/user'
	// import timer from '@/js_sdk/xbc-timer/timer-1.1.6.js'
	export default {
		data() {
			return {
				popupContent: '',
				type: 'center',
				msgType: 'success',
				exclusiveRights: [
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/phr_icon.svg?t=171403034554',
					// 	title: '健康管家（视频医生）',
					// 	children: [{
					// 			text: '一键呼叫视频医生'
					// 		},
					// 		{
					// 			text: '健康问题全部解决'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/gy_drug.svg?t=171403034554',
					// 	title: '药品折扣',
					// 	children: [{
					// 			text: '700多种常用药'
					// 		},
					// 		{
					// 			text: '2-9折购药优惠'
					// 		},
					// 		{
					// 			text: '满88元全国包邮'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/icon_green_way.svg?t=171403034554',
					// 	title: '门诊绿通',
					// 	children: [{
					// 			text: '权威专家号源'
					// 		},
					// 		{
					// 			text: '医院及科室推荐'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/IconMDT.svg?t=171403034554',
					// 	title: '全程陪诊',
					// 	children: [{
					// 			text: '专业陪诊人员'
					// 		},
					// 		{
					// 			text: '协助院内就诊'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/icon_green_way.svg?t=171403034554',
					// 	title: '重疾绿通',
					// 	children: [{
					// 			text: '三甲医院专家门诊预约'
					// 		},
					// 		{
					// 			text: '医院及科室推荐'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/icon_diagnosis.svg?t=171403034554',
					// 	title: '专家二诊',
					// 	children: [{
					// 			text: '初次患重大疾病'
					// 		},
					// 		{
					// 			text: '提供二次诊疗意见、治疗和用药方案'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/IconLeChengTCRT.svg?t=171403034554',
					// 	title: '住院安排',
					// 	children: [{
					// 			text: '初次患重大疾病'
					// 		},
					// 		{
					// 			text: '提供住院加急服务'
					// 		}
					// 	]
					// },
					// {
					// 	img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/IconPurchaseAssist.svg?t=171403034554',
					// 	title: '手术安排',
					// 	children: [{
					// 			text: '初次患重大疾病'
					// 		},
					// 		{
					// 			text: '提供手术加急服务'
					// 		}
					// 	]
					// }
				],
				equityData: [{
						title: '权益人姓名',
						value: '',
						key: 'name'
					},
					{
						title: '证件号',
						value: '',
						key: 'idNumber'
					},
					{
						title: '手机号',
						value: '',
						key: 'phoneNumber'
					},
					{
						title: '权益等待期(天)',
						value: '',
						key: 'activationPeriod'
					},
					{
						title: '权益开始时间',
						value: '',
						key: 'activationTime'
					},
					{
						title: '权益周期', //权益截止时间
						value: '',
						key: 'expiryDate'
					},
					// {
					// 	title: '权益服务剩余次数',
					// 	value: '',
					// 	key: 'number'
					// },
				],
				cardType:'',
				result:{}
			}
		},
		onLoad: function(option) {
			this.getDetails()
		},
		methods: {
			shareToggle() {
				this.$refs.share.open()
			},
			closeDrawer() {
				this.$refs.share.close();
			},
			btnItemDetails(currentItem){
				console.log(currentItem,'currentItem')
				uni.navigateTo({
					url: `/pages/code/serviceIntroduct?currentItem=${JSON.stringify(currentItem)}`
				});
			},
			 // 获取专属权益
			 getExclusiveRights(params) {
				ProductPrivileges(params).then(res => {
					console.log(res,'hzl')
					res.rows.forEach(item =>{
						this.exclusiveRights.push({
								img: 'https://agreement.medtreehealth.com/newHealth/assets/icon/phr_icon.svg?t=171403034554',
								title: item.privilegeName,
								Number: item.remarks,
								youxiaoqi: this.equityData[4].value,
								username: this.equityData[0].value,
								idNumber: this.equityData[1].value,
								phoneNumber: this.equityData[2].value,
								cardType:this.cardType,
								exclusiveRightsID:item.id,
								children: [],
								activationCode:this.result.activationCode
						})
						item.privilegeDescription.split(',').forEach(item =>{
							this.exclusiveRights[this.exclusiveRights.length-1].children.push({
								text: item
							})
						})
					})
				})
				console.log(this.exclusiveRights,'this.exclusiveRights')
			},
			getDetails() {
				BeneficiariesList(uni.getStorageSync('phone')).then(res => {
					let result = res.rows[0]
					this.result = result
					console.log(result,'result')
					console.log(result.activationCodes[0],'this.equityData')
					this.getExclusiveRights(result.activationCodes.product)
					this.cardType = result.idType
					for (let key in result) {
						this.equityData.forEach((item, index) => {
							if (key == item.key) {
								item.value = result[key]
							}
						})
					}
					for (let i in result.activationCodes) {
						this.equityData.forEach((item, index) => {
							if (i == item.key) {
								item.value = result.activationCodes[i]
							}
						})
					}
				}).finally(res => {
					this.equityData[5].value = this.getSimpleDate(this.addDays(this.equityData[4].value, Number(this
						.equityData[5].value)))
				})
			},
			addDays(date, days) {
				var result = new Date(date);
				result.setDate(result.getDate() + days);
				return result;
			},
			// 中国标准时间 转换成 年月日
			getSimpleDate(date) {
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				m = m < 10 ? ('0' + m) : m;
				var d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				var h = date.getHours();
				var minute = date.getMinutes();
				minute = minute < 10 ? ('0' + minute) : minute;
				var s = date.getSeconds();
				s = s < 10 ? '0' + s : s;
				return y + '-' + m + '-' + d
			}

		}
	}
</script>

<style>
	.myRights .shareview{
		text-align: center;
		line-height: 80rpx;
		border-bottom: 1px solid #ccc;
		/* font-size: 36rpx; */
	}
	.myRights .viewChild {
		padding: 20rpx;
		background: linear-gradient(rgba(145, 240, 255, 0.21) 0%, rgba(145, 240, 255, 0.1) 100%);
		line-height: 50rpx;
	}

	.myRights .viewChild .circular {
		display: inline-block;
		width: 16rpx;
		height: 16rpx;
		border-radius: 50%;
		background: rgb(41, 197, 136);
		margin-right: 10rpx;
	}

	.myRights .viewLis {
		line-height: 80rpx;
		padding: 20rpx;
		font-size: 36rpx;
		color: rgb(41, 197, 136);
		font-weight: bold;
	}

	.viewLis image {
		vertical-align: middle;
		margin-right: 10rpx;
	}

	.myRights .plainlk1 {
		border-color: transparent;
		background: rgb(41, 197, 136);
		color: rgb(255, 255, 255);
	}

	.myRights .hdsIGN_connent {
		background: #fff;
		padding: 20rpx;
		box-shadow: 10rpx 10rpx 10rpx 0.6;
		border-radius: 10px;
	}

	.myRights .hdsIGN_connent .viewLi {
		line-height: 80rpx;
		background: #fff;
	}

	.myRights .hdsIGN {
		/* background: rgb(255, 255, 255); */
		font-size: 1rem;
		padding: 0px 1.2rem;
	}

	.myRights .hdsIGN>h3::before {
		content: "";
		position: absolute;
		background: rgb(18, 205, 159);
		width: 0.2222em;
		height: calc(100% - 2.1667em);
		top: 1.1em;
		left: -0.6667em;
	}

	.myRights .hdsIGN>h3 {
		margin: 0px;
		font-size: 38rpx;
		padding: 0.8333em 0px;
		position: relative;
		color: rgba(0, 0, 0, 0.8);
	}

	.myRights h3 {
		font-size: 38rpx;
		font-weight: bold;
	}

	.myRights {
		width: 100%;
		height: 100vh;
		background: linear-gradient(rgba(145, 240, 255, 0.21) 0%, rgba(145, 240, 255, 0.1) 100%);
		overflow-x: hidden;
	}

	.status {
		position: absolute;
		left: 30rpx;
		top: 30rpx;
		font-size: 26rpx;
		color: rgb(255, 255, 255);
		background: rgb(50, 185, 188);
		padding: 10rpx 20rpx;
		border-radius: 20rpx 0rpx 30rpx;
	}

	.personal_jkhz_bg {
		min-height: 40rpx;
		margin-bottom: 20rpx;
		background: url('@/static/images/index/detail_top_bg.png') 0% 0% / 100% no-repeat;
		font-size: 1rem;
		padding: 30rpx;
	}
</style>